<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 7] Program Structure</TITLE>
<META NAME="author" CONTENT="Mark Grand">
<META NAME="date" CONTENT="Thu Jul 31 13:15:37 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="java">
<META NAME="title" CONTENT="Java Language Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Language Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch06_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 7</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch07_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JLR2-CH-7">7. Program Structure</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
Compilation Units<br>
<A HREF="ch07_02.htm">Packages</A><BR>
<A HREF="ch07_03.htm">The import Directive</A><BR>
<A HREF="ch07_04.htm">Documentation Comments</A><BR>
<A HREF="ch07_05.htm">Applications</A><BR>
<A HREF="ch07_06.htm">Applets</A><BR>

<p>
</DIV>

<P CLASS=para>
This chapter discusses
the higher levels of program structure for Java programs. The two
levels of organization discussed in this chapter are compilation
units and packages. A <I CLASS=emphasis>compilation unit</I> contains
the source code for one or more classes or interfaces. A
<I CLASS=emphasis>package</I> is a collection of related compilation units.<A NAME="CH07.STRUCT"></A>

<P CLASS=para>
This
chapter also discusses the two most common top-level Java program
architectures: applications and applets. An
<I CLASS=emphasis>application</I> is a stand-alone Java program that
can be run directly
from the command line (or other operating system environment).
An <I CLASS=emphasis>applet</I> is a Java program that must be run
from within another program, such as a Web browser. In the future,
applets will even be hosted by other environments,
such as cellular phones and personal digital assistants.

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JLR2-CH-7-SECT-1">7.1 Compilation Units</A></h2>

<P CLASS=para>
A compilation unit
is the highest-level syntactic structure that Java recognizes:


<p>
<img align=middle src="./figs/jlr0701.gif" alt="[Graphic: Figure from the text]" width=424 height=100 border=0>

<P CLASS=para>
Only one of the classes or interfaces declared in a compilation unit
can be declared <tt CLASS=literal>public</tt>.

<P CLASS=para>
A compilation
unit usually corresponds to a single source code file. However,
the Java language specification allows compilation units to be stored
in a database. If compilation units are stored in a database, the
limit of one <tt CLASS=literal>public</tt> class or interface per compilation
unit does not apply, as long as there is a way to extract the compilation
units from the database and place them in individual files that
contain no more than one <tt CLASS=literal>public</tt> class or interface
per file. This exception to the one <tt CLASS=literal>public</tt> class
or interface per compilation unit rule is useful if you are implementing
a Java development environment.

<P CLASS=para>
<A NAME="CH07.PACK"></A>Every compilation unit
is part of exactly one package. That package is specified by the
<tt CLASS=literal>package</tt> directive that appears at the beginning
of the compilation unit. If there is no <tt CLASS=literal>package</tt> directive,
the compilation unit is part of the default package.

<P CLASS=para>
<b>References</b>
<I CLASS=emphasis>ClassDeclaration</I> 5.4;
<A HREF="ch05_04.htm#JLR2-CH-5-SECT-4.1">Class Modifiers</A>;
<A HREF="ch07_03.htm#JLR2-CH-7-SECT-3">The import Directive</A>;
<A HREF="ch05_05.htm#JLR2-CH-5-SECT-5">Interface Declarations</A>;
<A HREF="ch05_05.htm#JLR2-CH-5-SECT-5.1">Interface Modifiers</A>;
<I CLASS=emphasis>PackageDirective</I> 7.2

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch06_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch07_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>The synchronized Statement</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Packages</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
